package com.tssm.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tssm.common.services.BaseServiceImpl;
import com.tssm.dao.SarcReferDAO;
import com.tssm.pojo.SarcRefer;
import com.tssm.service.SarcReferService;

@Service("sarcReferService")
public class SarcReferServiceImpl extends BaseServiceImpl<SarcRefer> implements SarcReferService {
	
	@Resource
	private SarcReferDAO sarcReferDAO;

	/**根据供应商ID、货物名称查询是否已经存在参照,返回true表示可以添加参照，返回false表示已经存在该参照**/
	public boolean queryReferBySupplierId(Long id, String name) {
		boolean flag = true;
		String hql = "from SarcRefer sr where sr.supplierid=" + id + " and sr.name='" + name +"'";
		List<SarcRefer> srlist = sarcReferDAO.find(hql);
		if(srlist.size() > 0) flag=false;
		return flag;
	}
	/**根据供应商ID查询所属货物参照**/
	public List<SarcRefer> queryReferById(Long id, int firstIndex, int pageSize) {
		String hql = "from SarcRefer sr where sr.supplierid="+id;
		List<SarcRefer> srlist = sarcReferDAO.find(hql, firstIndex, pageSize);
		if(srlist.size() > 0) return srlist;
		else return new ArrayList<SarcRefer>();
	}
	/**根据供应商ID查询货物参照数量**/
	public Integer queryReferCountById(Long id) {	  
		return sarcReferDAO.queryReferCountById(id);	
	}

}
